Skip to content

Share code the Core internals wrote twice, tidy names, messages and comments - #306

Merged
electricessence merged 4 commits into
masterfrom
refactor/wave-b-r2
Dec 3, 2026
Merged

electricessence merged 4 commits into
masterfrom
refactor/wave-b-r2

Conversation

@electricessence

Copy link
Copy Markdown
Collaborator

Internal refactor: code the Core internals wrote twice is shared, flag parameters become named methods, internal members of internal types become public, messages that said what is wrong now say what to do, and comments and names follow the written rules. No public API change (the PublicAPI files are untouched) and no change to generated code.

What changed

Shared code, flags replaced by named methods (cost: none per call or per row: every change is on a declaration, chain-building or error path, or a property read or a call that inlines)

  • A capture's task is read by two methods (Started: only the terminal has started; Awaited: also refuses an open stream) instead of one with a bool, and marks its stream open and closed with BeginStream and EndStream.
  • A set of captures is extended with WithOnCommand or WithOnQuery instead of a bool; the word the messages use ("command" or "query") comes from the set's own Noun. A capture of the return code beside a call that reads it is refused by one method on the set.
  • The eight capture overloads of a bound call share one helper; a definition's call that reads outputs builds its command through the method a plain call uses; the test for "procedure metadata still to be read" is one property on the name set; the declared type name of an output member is read by the row map's own attribute reader.
  • The output definitions share one place that names the definition in a refusal and one that checks a decimal's precision and scale; ReturnCode keeps the type-independent part in a non-generic class.
  • The documentation samples read SAMPLES_BLOG_CONNECTION with string.IsNullOrWhiteSpace, so an empty value falls back to LocalDB as an unset one does.

Rules and names

  • Members of internal types are public or private, not internal. ProcedureKey becomes a primary-constructor struct (the analyzer asks for it once its constructor is public); the tests and benchmarks that reach these members by reflection look for public members now.
  • Messages that said what is wrong now also say what to do: a blank command, a command whose type does not match the connection's provider, concurrent use of a single connection, a reader of the wrong type, and a transaction without a connection. Two tests that pin text follow it, and the release note no longer quotes the transaction text.
  • Names: KeyOf (builds the procedure key), _handedOver (the producer's count of rows handed over), buildsAfterReading (the generator's former styleB), reading (the row reader's "rows still to map").
  • Comments: the no-timeout dispose rationale is written once, in the ChunkProducer header; comments that cited a record that is not in the repository now say so or drop the citation; the three sentences that Stream and StreamBuffered repeated are one shared include (stream-your-thread).

Behavior notes

  • Two messages change text on purpose: the transaction-without-connection message (both packages) and the messages above; the return-code capture of a captured ExecuteReturnAsync shows the typed form of the call in its messages (ExecuteReturnAsync<int>()), like the uncaptured one.
  • CaptureSet.WithOnQuery and WithOnCommand rely on the set's kind never changing, as the comment says; a Debug assertion checks it. Every caller starts from a null set.

Left out: the generator's bool parameters that choose between two emitted shapes (they predate this change; an owner decision), the benchmark's constructor lookup for the name set, and two messages the list did not name (DbQuery.cs blank-command text and DbConnectionProvider.Take).

Cost

None per call or per row.

Reviews

Two Haiku lenses (correctness of the consolidations; rules, names, tests and docs) read the diff. Applied: argument grouping, => placement, _handedOn renamed to match the file's wording, the lost byte order marks restored, the stale release-note quote, one more shared include, and the Debug assertion. Not applied: the generator's bool parameters and the two out-of-list messages (above).

Checks: Release 16,151 and Debug 16,130 tests pass (16 skipped), 189 generator tests, 0 build warnings on every target framework, 267 sample checks, dotnet format style and analyzers clean on all 28 checks, DocFX 0 warnings, the style scan clean.

🤖 Generated with Claude Code

electricessence and others added 3 commits December 2, 2026 17:17
…s with named methods

No public API change and no change to generated code. The cost is none per call or per row: every change is on a declaration, chain-building or error path, or is a property read or a call that inlines.

- A capture's task is read by two methods, one that only needs the terminal to have started (AsTask) and one that also refuses an open stream (await), instead of one method taking a bool. A capture marks its stream open and closed with two methods, not a bool.
- A set of captures is extended with WithOnCommand or WithOnQuery instead of a bool; the word the messages use ("command" or "query") now comes from the set's own Noun, in one place. A capture of the return code beside a call that reads it is refused by one method on the set, which the command and the bound call both use.
- The capture of an output model builds its display text once, and the return-code capture of a captured ExecuteReturnAsync now shows the typed form of the call in its messages, like the uncaptured one.
- The eight capture overloads of a bound call share one helper that adds the capture and hands back its handle.
- A definition's call that reads outputs builds its command through the same method as a plain call, then adds the outputs, instead of repeating its ten lines. The test for a procedure whose metadata is still to be read is one property on the name set, used by the command and the definition runner.
- The declared type name of an output member is read by the same attribute reader the row map uses (Decoration), instead of a second walk over the attributes. The decimal call texts in the "no output matches" message come from the same two helpers the argument checks use, with the same wording.
- The output definitions share one place that names the definition in a refusal, one place that checks a decimal's precision and scale, and the model's refusal no longer repeats its own catch block.
- ReturnCode keeps the type check and the message in a non-generic class, and the generic one only what depends on the type.
- CaptureNames: the redundant null-forgiving operators after the white-space check are removed.
- The documentation samples read SAMPLES_BLOG_CONNECTION with string.IsNullOrWhiteSpace, so an empty value falls back to LocalDB as an unset one does.

Checks: solution Release build with 0 warnings on every target framework; Core.Tests Release 16151 passed; Generator.Tests Release 189 passed; dotnet format style and analyzers at info severity on Core, Core.Tests and the samples: 0 findings; docfx build with 0 warnings and 0 errors; style scan clean.

Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>
Members of internal types are public or private, not internal (the channel and dataflow pumps, the parameter-name caches and sets, the schema-name reader, the view builders, the row reader, and the row-map helper types). ProcedureKey becomes a primary-constructor struct, as the analyzer asks once its constructor is public. The tests and benchmarks that reach these members by reflection look for public members now.

Messages that said what is wrong now also say what to do: a blank command, a command whose type does not match the connection's provider, concurrent use of a single connection, a reader of the wrong type, and a transaction with no connection (the SQL Server package test that pins the transaction text and the blank-command test follow the new text).

Names and comments:
- the ExpressiveCommandBase method that built the procedure key is called KeyOf, and the producer's count of rows already handed on is _handedOn, so neither shares a word with a type or with the one-shot flag of the streams;
- the generator's styleB flag is buildsAfterReading, and the Slot calls name their bool arguments;
- the RowReader stream flag that meant "rows still to map" is reading.

Comments only: a comment about DbQuery no longer sits above ExpressiveCommandBase; the long comments there are wrapped and placed over the members they describe; the no-timeout dispose rationale is written once, in the ChunkProducer header, and the buffer and the stream point to it; comments that cited a spike or a proof now say the record is not kept in the repository, or drop the citation; the CapturedStream header is shorter and states why ToException may cast; a dangling comment in RowMap is gone; the TextNameCache note moved into its remarks; two RowReader doc blocks are indented, and the second ToArray path says why its sink is disposed by hand; the Emitter header no longer cites a missing file and is wrapped at 80 columns; the three sentences that Stream and StreamBuffered repeat in IMappedQuery are one include.

Cost: none (no per-call or per-row code changed).

Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>
…g assert

Group the arguments of the decimal layout calls and of the output command
build, put the `=>` of the procedure key on its own line, and rename the
chunk producer's count of handed-over rows to match its comment. Drop a
comment in the row reader that repeated an earlier one.

Restore the UTF-8 byte order mark on the two `Transaction.CreateCommand.cs`
files. The message for a transaction without a connection now says it can
happen after the transaction completed, not only the one way; the test that
pins it and the release note are updated, and the note no longer quotes the
text.

The mapped query's `Stream` and `StreamBuffered` now take the three
sentences on the read thread from the `stream-your-thread` include that the
interface already uses, so the two cannot drift.

`CaptureSet.WithOnQuery` and `WithOnCommand` assert, in Debug builds, that
the set they extend was made for the same kind of caller. No change in
Release.

No behavior change in Release. Checks: Release and Debug builds of the
solution with 0 warnings; Core tests in Release (16151 passed) and Debug
(16130 passed, 16 skipped); generator tests (189 passed); `dotnet format`
style and analyzers at info severity, 0 findings on Core, MSSqlClient and
Core.Tests; docs build with 0 warnings.

Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>
# Conflicts:
#	docsite/articles/release-notes.md
@electricessence
electricessence merged commit 931195a into master Dec 3, 2026
8 checks passed
@electricessence
electricessence deleted the refactor/wave-b-r2 branch December 3, 2026 01:27
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant